package controller

import (
	"user-center/dto"
	"user-center/query"
	"user-center/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(SysRolesController{
		sysRolesService: service.NewSysRolesService(),
	})
}

type SysRolesController struct {
	sysRolesService service.SysRolesService
}

// 查询
// @Router [get] [/sysroles/:id]
func (m SysRolesController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysRolesService.Get(id)
}

// 增加
// @Router [post] [/sysroles]
func (m SysRolesController) Save(c *gin.Context, dto *dto.SysRolesDTO) any {
	dto.Id = ""
	return m.sysRolesService.Save(dto)
}

// 修改
// @Router [put] [/sysroles/edit]
func (m SysRolesController) UpdateById(c *gin.Context, dto *dto.SysRolesDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysRolesService.UpdateById(dto)

}

// 删除
// @Router [delete] [/sysroles/:id]
func (m SysRolesController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysRolesService.DeleteById(id)
}

// 查询列表
// @Router [post] [/sysroles/page]
func (m SysRolesController) QueryPage(c *gin.Context, query *query.SysRolesQueryDTO) any {
	return m.sysRolesService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/sysroles/list]
func (m SysRolesController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.sysRolesService.QueryList(query)
}
